package com.artifex.mupdf.viewer

import androidx.lifecycle.LiveData

// In your repository
class BookRepository(
    private val bookDao: BookDao,
) {
    private val booksCache = mutableListOf<Book>()


    fun getBooks(): LiveData<List<Book>> {
        return if (booksCache.isEmpty()) {
            bookDao.getAllBooks()
        } else {
            object : LiveData<List<Book>>() {
                override fun onActive() {
                    super.onActive()
                    value = booksCache
                }
            }
        }
    }
}